/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin		 	*/
/*	Project:	GoLib-1.0.0			*/
/*	Author:		gong_libin			*/
/*	Date:		2016_01_01			*/
/*	File:		GoOut.go			*/
/********************************************************/

package GoGlb

import (
	"fmt"
	"reflect"
)

// GO_SUCCESS int = 0
// GO_FAILURE int = -1

const (
	GO_OT_SPCE	int = 0x04
	GO_OT_ENTR	int = 0x08
)

func GoPrtHx(f, l int, b []byte) {
	GoPrint("Pkt[%d]:", l - f);
	for i, v := range b[f : l] {
		switch {
			case 0 == i % GO_OT_ENTR:
				fmt.Printf("\n")
			case 0 == i % GO_OT_SPCE:
				fmt.Printf(" ")
		}
		fmt.Printf("0x%02x ", v);
	}
	fmt.Println()
}

func GoPrtln(args ...interface{}) {
	fmt.Println(args...)
}

func GoPrint(format string, args ...interface{}) {
	fmt.Printf(format, args...)
}

func GoDebug(format string, args ...interface{}) {
	fmt.Printf("[DEBUG]: ")
	fmt.Printf(format, args...)
	fmt.Println()
}

func GoError(err error) int {
	var ret int = 0
	if nil != err {
		fmt.Printf("[ERROR]: %s\n", err)
		ret = -1
	}
	return ret
}

func GoSlice(f, l int, args ...interface{}) {
	in := fmt.Sprint(args...)

	out := in[l : f]
	for _, v := range out {
		GoPrint("%c", v)
	}
	GoPrtln()
}

func GoValOf(format string, v interface{}) {
	GoPrtln(format, reflect.ValueOf(v))
}

func GoValue(format string, args ...interface{}) string {
	return fmt.Sprintf(format, args...)
}
